import {actionTypes} from './index'
import {fromJS} from 'immutable'
import {_getLanSetData, _setLanSetData} from "@/http/api";
import { actionFunc as submitBtnActionFunc} from '@/components/SubmitBtn/store'

const updateFormData = (value) => ({
    type: actionTypes.UPDATE_FORMDATA,
    value: fromJS(value)
})


export const getLanSetData = () => {
    return (dispatch) => {
        _getLanSetData().then(res => {
            dispatch(updateFormData(res.formData))
        })
    }
}
export const setLanSetData = (values) => {
    return (dispatch) => {
        dispatch(submitBtnActionFunc.activateLoading())
        _setLanSetData(values).then(res => {
            if (res.status === 1) {
                dispatch(submitBtnActionFunc.closeLoading())
                dispatch(updateFormData(values))
            }
        })
    }
}
